# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Contributor: Florian Walch <florian+aur@fwalch.com>

pkgbase=lua-mpack
pkgname=(lua51-mpack lua52-mpack lua53-mpack lua-mpack)
pkgver=1.0.10
pkgdesc="libmpack lua binding"
pkgrel=1
arch=('loong64' 'x86_64')
url='https://github.com/libmpack/libmpack-lua'
depends=('libmpack')
makedepends=('lua51' 'lua52' 'lua53' 'lua')
license=('MIT')
source=("libmpack-lua-${pkgver}.tar.gz::https://github.com/libmpack/libmpack-lua/archive/${pkgver}.tar.gz")
sha256sums=('b58a25a0b48e1ec584beee6c80e0e31182dad7a45005ce58e88e6cfff3a3f3e4')

build() {
  cd "libmpack-lua-${pkgver}"

  gcc -O2 -fPIC -DMPACK_USE_SYSTEM -I/usr/include/lua5.1 -c lmpack.c -o lmpack.o
  gcc -shared -lmpack -o mpack.so.5.1 lmpack.o

  gcc -O2 -fPIC -DMPACK_USE_SYSTEM -I/usr/include/lua5.2 -c lmpack.c -o lmpack.o
  gcc -shared -lmpack -o mpack.so.5.2 lmpack.o

  gcc -O2 -fPIC -DMPACK_USE_SYSTEM -I/usr/include/lua5.3 -c lmpack.c -o lmpack.o
  gcc -shared -lmpack -o mpack.so.5.3 lmpack.o

  gcc -O2 -fPIC -DMPACK_USE_SYSTEM -I/usr/include -c lmpack.c -o lmpack.o
  gcc -shared -lmpack -o mpack.so.5.4 lmpack.o
}

package_lua51-mpack() {
  pkgdesc='Simple implementation of msgpack in C Lua 5.1'
  depends+=('lua51')

  cd "libmpack-lua-${pkgver}"
  install -Dm755 mpack.so.5.1 "${pkgdir}/usr/lib/lua/5.1/mpack.so"
  install -Dm644 LICENSE-MIT "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_lua52-mpack() {
  pkgdesc='Simple implementation of msgpack in C Lua 5.2'
  depends+=('lua52')

  cd "libmpack-lua-${pkgver}"
  install -Dm755 mpack.so.5.2 "${pkgdir}/usr/lib/lua/5.2/mpack.so"
  install -Dm644 LICENSE-MIT "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_lua53-mpack() {
  pkgdesc='Simple implementation of msgpack in C Lua 5.3'
  depends+=('lua53')

  cd "libmpack-lua-${pkgver}"
  install -Dm755 mpack.so.5.3 "${pkgdir}/usr/lib/lua/5.3/mpack.so"
  install -Dm644 LICENSE-MIT "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_lua-mpack() {
  pkgdesc='Simple implementation of msgpack in C Lua 5.4'
  depends+=('lua')

  cd "libmpack-lua-${pkgver}"
  install -Dm755 mpack.so.5.4 "${pkgdir}/usr/lib/lua/5.4/mpack.so"
  install -Dm644 LICENSE-MIT "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

# vim:set sw=2 sts=2 et:
